# Copyright 2010 Google Inc. All Rights Reserved
# Makefile for TXM /test directory
# Erlang is not in 3rd party, the blaze BUILD will have to wait.
# Author jacoby@google.com (Jacoby Thwaites)

INCLUDE := ../include
EBIN 	:= ../ebin
BEAM	:= .beam
COOKIE	:= test
NAME := test

.SUFFIXES: .erl .beam

.erl.beam:
	erlc +debug_info -I $(INCLUDE) -o $(EBIN) $<

ERL =	-name $(NAME) -setcookie $(COOKIE) -boot start_clean

# Test modules (mocks & tests)
MOCKS 	:= prog_mock client_mock
TESTS	:= graph_tests \
	node_srv_tests \
	nr_set_tests nr_set_dict_tests \
	process_cache_tests \
	prog_srv_tests prog_tests \
	search_tests \
	struct_tests \
	txm_util_tests \
	view_db_tests view_fsm_tests \
	web_util_tests \
	xj_tests
MODS	:= $(MOCKS) $(TESTS)

all: compile run

compile: $(MODS:%=%.beam)

shell:
	cd $(EBIN) && erl -name $(NAME) -setcookie $(COOKIE)

run: 
	cd $(EBIN) && erl -noshell -name $(NAME) -setcookie $(COOKIE) \
		 $(foreach test, $(TESTS), -s eunit test $(test)) \
		-s init stop

# Cleans .beam files in ebin directory and Mnesia schema on the test node.
.PHONY: clean
clean:
	-rm $(addprefix $(EBIN)/, $(addsuffix $(BEAM), $(MODS)))
	-rm -rf $(addprefix $(EBIN)/, Mnesia.$(NAME))
